package com.example.controller;

import com.example.entity.po.Teacher;
import com.example.entity.po.Teaching;
import com.example.entity.vo.PlaceClassroom;
import com.example.entity.vo.TeachingVo;
import com.example.utils.ResultUtils;
import com.example.service.TeachingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RestController
public class TheachingController {
    @Autowired
    public TeachingService teachingService;

    @GetMapping("/teachingList")
    public ResultUtils queryTeaching(){
        List<TeachingVo> theachings=teachingService.queryTeaching();
        if (theachings.size()==0){
            return ResultUtils.Failure("查询授课信息失败",null);
        }else {
            return ResultUtils.Successful("查询授课信息成功",theachings);
        }
    }

    @PostMapping("/deleteTeaching")
    public ResultUtils deleteTheaching(int teachingId){
        int res=teachingService.deleteTeaching(teachingId);
        if (res==0){
            return ResultUtils.Failure("删除授课信息失败",null);
        }else {
            return ResultUtils.Successful("删除授课信息成功",null);
        }
    }

    @PostMapping("/addTeaching")
    public ResultUtils addTeaching(@RequestBody Teaching teaching){
        int res= teachingService.addTeaching(teaching);
        if (res==0){
            return ResultUtils.Failure("添加授课信息失败,请检查授课教室是否已被使用",null);
        }else {
            return ResultUtils.Successful("添加授课信息成功",null);
        }
    }

    @PostMapping("/fuzzyTeaching")
    public ResultUtils fuzzyTeacher(String teachingName){
        List<TeachingVo> teaching=teachingService.fuzzyTeaching(teachingName);
        if (teaching.size()==0){
            return ResultUtils.Failure("搜索失败或无该该授课信息",null);
        }else {
            return ResultUtils.Successful("搜索授课信息成功",teaching);
        }
    }

}
